package com.erp.order.purchasing.dao.impl;

import com.erp.hr.base.dao.impl.BaseDaoImpl;
import com.erp.hr.base.util.CommonUtils;
import com.erp.order.purchasing.dao.InquiryListSupplierDao;
import com.erp.order.purchasing.model.InquiryListSupplier;
import org.redragon.framework.hibernate.DaoSupport;
import org.redragon.framework.hibernate.model.Pages;
import org.redragon.framework.util.DaoCRUDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 询价单供应商 持久实现层
 * @Author: syz
 * @blame syz
 * @CreateTime: 2021/4/6
 */
@Repository
@Transactional
public class InquiryListSupplierDaoImpl extends BaseDaoImpl<InquiryListSupplier> implements InquiryListSupplierDao {

    /**
     * dao支持
     */
    @Autowired
    private DaoSupport daoSupport;


    @Override
    public InquiryListSupplier getDataObject(String s) {
        return null;
    }

    /**
     * 根据条件查询对象集合
     * @param inquiryListSupplier 询价供应商对象
     * @return 对象集合
     */
    @Override
    public List<InquiryListSupplier> getDataObjects(InquiryListSupplier inquiryListSupplier) {
        String sql =
                "SELECT " +
                    "ils.* " +
                "FROM " +
                    "inquiry_list_supplier ils " +
                "WHERE " +
                    "ils.is_del = :isDel ";
        Map<String, Object> args = new HashMap<>();
        args.put("isDel", CommonUtils.IS_DEL_NO);
        sql += DaoCRUDUtil.getSQLSearch(inquiryListSupplier, "inquiryListId", "and ils.", args);
        sql += DaoCRUDUtil.getSQLSearch(inquiryListSupplier, "supplierId", "and ils.", args);
        return daoSupport.selectDataSql(
                sql,
                new HashMap<String, Class<?>>(){{
                    put("ils", InquiryListSupplier.class);
                }},
                args);
    }

    @Override
    public List<InquiryListSupplier> getDataObjectsForDataAuth(String s, Pages pages, InquiryListSupplier inquiryListSupplier) {
        return null;
    }

    /**
     * 根据询价id获取对象集合
     * @param id 询价id
     * @return 对象集合
     */
    @Override
    public List<InquiryListSupplier> getListByInquiryListId(Long id) {
        return daoSupport.selectDataSql(
                "SELECT " +
                    "ils.* " +
                "FROM " +
                    "inquiry_list_supplier ils " +
                "WHERE " +
                    "ils.inquiry_list_id = :id " +
                "AND " +
                    "ils.is_del = :isDel",
                new HashMap<String, Class<?>>(){{
                    put("ils", InquiryListSupplier.class);
                }},
                new HashMap<String, Object>(){{
                    put("id", id);
                    put("isDel", CommonUtils.IS_DEL_NO);
                }});
    }

}